using UnityEngine;
using UnityEngine.UI;

public class PlayerPrefsTest : MonoBehaviour
{
    void Start()
    {
        string context = "";
        Text res = GameObject.Find("Text").GetComponent<Text>();

        bool exist3 = PlayerPrefs.HasKey("TestFloat");

        context = context + "Has TestFloat Key: " + exist3 + "\n";

        if (PlayerPrefs.GetInt("TestInt") != 9)
        {
            PlayerPrefs.SetFloat("TestFloat", 1.0f);
            PlayerPrefs.SetInt("TestInt", 10);
            PlayerPrefs.SetString("TestString", "Hello World");
        }

        context = context
            + PlayerPrefs.GetFloat("TestFloat").ToString() + " " 
            + PlayerPrefs.GetInt("TestInt").ToString() + " "
            + PlayerPrefs.GetString("TestString") + "\n";

        PlayerPrefs.Save();

        PlayerPrefs.DeleteKey("TestFloat");
        bool exist = PlayerPrefs.HasKey("TestFloat");

        context = context + "Delete TestFloat Key: " + !exist + "\n";

        PlayerPrefs.DeleteAll();
        bool exist1 = PlayerPrefs.HasKey("TestInt");
        bool exist2 = PlayerPrefs.HasKey("TestString");
        if (!exist1 && !exist2)
            context = context + "Delete All Keys";
        
        PlayerPrefs.SetInt("TestInt", 9);
        PlayerPrefs.SetFloat("TestFloat", 2.0f);
        PlayerPrefs.SetString("TestString", "Record Second Times");
        PlayerPrefs.Save();

        res.text = context;
    }
}
